package cn.apthink.mybatisplus;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.fill.Property;

public class MyBatisPlusGenerator {
	private static String tables = "SystemParameter,UserParameter,Department";
	
	// 处理 all 情况
	protected static List<String> getTables() {
		return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
	}

	public static void main(String[] args) {
		FastAutoGenerator.create("jdbc:sqlite://D:/gitee/ApthinkServer/db/apthink.sqlite3", "root", "123456")
				// 全局配置
				.globalConfig((builder) -> {
					builder.author("David唐") // 设置作者
							.enableSwagger() // 开启 swagger 模式
//							.outputDir("D://"); // 指定输出目录
							.outputDir("D:\\gitee\\ApthinkServer\\src\\main\\java");
				})
				// 包配置
				.packageConfig((scanner, builder) -> {
					builder.parent("cn.apthink.mybatisplus");
				}).templateConfig(builder -> {
					// 不生成Controller
					builder.controller(null);
				})
				// 策略配置
				.strategyConfig(builder -> {					
					builder.addInclude(getTables());
					builder.entityBuilder().addTableFills(new Property("createtime", FieldFill.INSERT));
					builder.entityBuilder().addTableFills(new Property("updatetime", FieldFill.UPDATE));
					builder.serviceBuilder().formatServiceFileName("%sService")
							.formatServiceImplFileName("%sServiceImpl")
							.superServiceClass("com.baomidou.mybatisplus.solon.service.IService")
							.superServiceImplClass("com.baomidou.mybatisplus.solon.service.impl.ServiceImpl").build();
					// entity的策略配置
					builder.entityBuilder().disableSerialVersionUID().enableLombok().enableTableFieldAnnotation()
							.naming(NamingStrategy.no_change)
							.columnNaming(NamingStrategy.no_change)
							.formatFileName("%sEntity").build();
				}).execute();
	}
}
